/****************************************************************
*****************************************************************/

*by Xiaodong Fan, fanxiaodong@gmail.com

#delimit ;

cap log close;
clear all;
drop _all;
set more 1;
pause on;

log using log_MSM_healthexp_plot.log, replace;

global gpicsdir "pics_healthexp";
global gdtadir ".";

include do_globals.do;
global gvN0 = 18 + ${gIcol}*4;

/***********************************************
  Moments generated in Fortran program
  *2 stands for unanticipated case.
************************************************/
local lvmoments lfpr lnw sdlnw lnw_fd alfpr1to0 alfpr0to1 C ssa lfpr_diff_E2G lfpr_diff_G2B lfpr_diff_B2D lfpr_pt plnw41;


*plot now;
use ${gdtadir}/dta_MSM_healthexp.dta if t>=18, clear;


local lvprofiles A H C I olabor inc irecss V lfpr lnw sdlnw;

local lvcond "if t<${gvNT}";


forvalues iv=41/55 {;
   cap gen d_lfpr`iv' = lfpr`iv' - lfpr0;
};

sum d_lfpr41 d_lfpr46 d_lfpr51 if t>=51 & t<=80;  // 41: health status stays as 50, 46: and leisure taste;

sum d_lfpr41 d_lfpr46 d_lfpr51 if t>=55 & t<=70;

pause;

foreach iv in lfpr H {;
   if ("`iv'"=="lfpr") {;
      local lviv "LFPR";
      local lvpos=7;
   };
   else if ("`iv'"=="lnw") {;
      local lviv "Log Wages";
      local lvpos=5;
   };
   else if ("`iv'"=="lnw_fd") {;
      local lviv "Log Wages (FD)";
      local lvpos=5;
   };
   else if ("`iv'"=="H") {;
      local lviv "Human Capital";
      local lvpos=7;
   };
   else if ("`iv'"=="I") {;
      local lviv "Investment";
      local lvpos=2;
   };
   else {;
      local lviv "`iv'";
      local lvpos=6;
   };


   line `iv'0 `iv'41 `iv'42 `iv'43 `iv'44 `iv'45 t `lvcond', graphregion(color(white))
       lpattern("l" "_" "_." "-" "-." ".")  xtitle("Age") ytitle("`lviv'")
       xlabel(20(10)${gvNT},grid) xscale(range(${gvN0} ${gvNT})) 
       legend(ring(0) pos(`lvpos') col(1) keygap(*1) symxsize(*1) symysize(*0.5) 
              order(1 "Baseline" 2 "Fixed at 50" 3 "All Excellent" 
                    4 "All Good" 5 "All Bad" 6 "All Disabled"));
   graph export ${gpicsdir}/eps_he_`iv'_41to45.eps, replace;

   line `iv'0 `iv'46 `iv'47 `iv'48 `iv'49 `iv'50 t `lvcond', graphregion(color(white))
       lpattern("l" "_" "_." "-" "-." ".")  xtitle("Age") ytitle("`lviv'")
       xlabel(20(10)${gvNT},grid) xscale(range(${gvN0} ${gvNT})) 
       legend(ring(0) pos(`lvpos') col(1) keygap(*1) symxsize(*1) symysize(*0.5) 
              order(1 "Baseline" 2 "Fixed at 50" 3 "All Excellent" 
                    4 "All Good" 5 "All Bad" 6 "All Disabled"));
   graph export ${gpicsdir}/eps_he_`iv'_46to50.eps, replace;

   line `iv'0 `iv'51 `iv'52 `iv'53 `iv'54 `iv'55 t `lvcond', graphregion(color(white))
       lpattern("l" "_" "_." "-" "-." ".")  xtitle("Age") ytitle("`lviv'")
       xlabel(20(10)${gvNT},grid) xscale(range(${gvN0} ${gvNT}))
       legend(ring(0) pos(`lvpos') col(1) keygap(*1) symxsize(*1) symysize(*0.5) 
              order(1 "Baseline" 2 "Fixed at 50" 3 "All Excellent" 
                    4 "All Good" 5 "All Bad" 6 "All Disabled"));
   graph export ${gpicsdir}/eps_he_`iv'_51to55.eps, replace;

};

cap log close;


